
package services

import (
	"beego_blog/models"
	"net/url"
	"strconv"
)

type SchoolService struct {
	baseService
}

func (c *SchoolService) Add(params url.Values) {
	school := models.School{}
	
	school.Id, _ = strconv.Atoi(params.Get("id"))
	school.Name = params.Get("name")
	school.Addr = params.Get("addr")

	if _, err := c.o.Insert(&school); err != nil {
		// todo
	} else {
		// todo
	}

}

func (c *SchoolService) Delete(params url.Values) {
	id, err := strconv.Atoi(params.Get("id"))
	if err != nil {
		// todo
	} else {
		if _, err := c.o.Delete(&models.School{Id: id}); err != nil {
			// todo
		} else {
			// todo
		}
	}
}

func (c *SchoolService) Query(params url.Values) []*models.School{
	school := []*models.School{}
	c.o.QueryTable(new(models.School).TableName()).OrderBy("-id").All(&school)
	return school
}

func (c *SchoolService) Update(params url.Values) {
	school := models.School{}
	
	school.Id, _ = strconv.Atoi(params.Get("id"))
	school.Name = params.Get("name")
	school.Addr = params.Get("addr")

	if _, err := c.o.Update(&school); err != nil {
		// todo
	} else {
		// todo
	}

}
	
